package org.jeecg.modules.mall.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.annotation.ApiLogin;
import org.jeecg.com.util.ThirdSessionHolder;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.TenantContextHolder;
import org.jeecg.config.ApiVersion;
import org.jeecg.config.ApiVersionConstant;
import org.jeecg.config.WebConfig;
import org.jeecg.modules.mall.entity.MallCollectHotel;
import org.jeecg.modules.mall.service.IMallCollectHotelService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: mall_collect_hotel
 * @Author: jeecg-boot
 * @Date:   2023-04-27
 * @Version: V1.0
 */
@Api(tags="酒店收藏")
@RestController
@RequestMapping("/mall-api/collect-hotel")
@Slf4j
public class MallCollectHotelController extends WebConfig {
	@Resource
	private IMallCollectHotelService mallCollectHotelService;

	/**
	 * 分页列表查询
	 *
	 * @param mallCollectHotel
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="mall_collect_hotel-分页列表查询", notes="mall_collect_hotel-分页列表查询")
	@GetMapping(value = "/list")
	@ApiLogin
	@ApiVersion(group = ApiVersionConstant.FAP_MALLAPI101)
	public Result<IPage<MallCollectHotel>> queryPageList(MallCollectHotel mallCollectHotel,
														 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														 HttpServletRequest req) {
		LambdaQueryWrapper<MallCollectHotel> queryWrapper = QueryGenerator.initQueryWrapper(mallCollectHotel, req.getParameterMap()).lambda();
		String userId = ThirdSessionHolder.getUserId();
		queryWrapper.eq(MallCollectHotel::getUserId,userId);
		Page<MallCollectHotel> page = new Page<MallCollectHotel>(pageNo, pageSize);
		IPage<MallCollectHotel> pageList = mallCollectHotelService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param mallCollectHotel
	 * @return
	 */
	@AutoLog(value = "mall_collect_hotel-添加")
	@ApiOperation(value="mall_collect_hotel-添加", notes="mall_collect_hotel-添加")
	@ApiLogin
	@ApiVersion(group = ApiVersionConstant.FAP_MALLAPI101)
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody MallCollectHotel mallCollectHotel) {
		String tenantId = TenantContextHolder.getTenantId();
		String userId = ThirdSessionHolder.getUserId();
		mallCollectHotel.setUserId(userId);
		mallCollectHotel.setTenantId(tenantId);
		mallCollectHotelService.save(mallCollectHotel);
		return Result.OK("添加成功！");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "mall_collect_hotel-通过id删除")
	@ApiOperation(value="mall_collect_hotel-通过id删除", notes="mall_collect_hotel-通过id删除")
	@ApiLogin
	@ApiVersion(group = ApiVersionConstant.FAP_MALLAPI101)
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		mallCollectHotelService.removeById(id);
		return Result.OK("删除成功!");
	}

}
